def is_prime(a):
    if a == 1: return False
    test = True
    k = a - 1
    while k > 1:
        if not a % k: test = False
        break
        k -= 1
    return test
n = input()
r = []
for i in range(len(n)):
    for k in range(i + 1, len(n) + 1):
        a = int(n[i:k])
        if is_prime(a): r +=[a]
if 999<max(r)<10000:
    print(max(r) if r else 0)
else:
    print(0)
